/**
 * Project: lionbule-other
 * 
 * File Created at 2012-6-28
 * $Id$
 * 
 * Copyright 1999-2100 Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.dm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

/**
 * PathService.
 * 
 * @author LionBule 2012-6-28 下午11:08:25
 */
public class PathService {
    public static Map<String, Integer> queryAllPath() {
        PathService t = new PathService();
        try {
            return t.query();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private Connection getConn() throws Exception {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection conn = DriverManager.getConnection("jdbc:mysql://10.250.4.98:3306/agds", "agds",
                "agds");
        return conn;
    }

    private Map<String, Integer> query() throws Exception {
        Map<String, Integer> result = new HashMap<String, Integer>();
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = getConn();
            String baseSql = "select id,full_path from agds_dm_path";
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            rs = stmt.executeQuery(baseSql);
            while (rs.next()) {
                result.put(rs.getString("full_path"), rs.getInt("id"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            rs.close();
            stmt.close();
            conn.close();
        }
        return result;
    }
}
